package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.myapplication.db.domain.AccountBean;

import java.util.List;

public class ItemAdapter extends ArrayAdapter<AccountBean> {
    public ItemAdapter(@NonNull Context context, int resource, List<AccountBean> objects) {
        super(context, resource,objects);
    }

    //每个子项被滚动到屏幕内的时候会被调用
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
//        得到当前子项的实例
        AccountBean accountBean = getItem(position);

        //为每一个子项加载设定的布局
        View view = LayoutInflater.from(getContext()).inflate(R.layout.account_item, parent, false);
        //分别获取 image view 和 textview 的实例
        ImageView itemImage = view.findViewById(R.id.item_mainlv_lv);
        EditText itemTitle = view.findViewById(R.id.item_mainlv_tv_title);
        EditText itemMoney = view.findViewById(R.id.item_mainlv_tv_money);
        EditText itemTime = view.findViewById(R.id.item_mainlv_tv_time);
        // 设置要显示的图片和文字
        itemImage.setImageResource(accountBean.getImage(accountBean.getIndex(accountBean.getType())));
        itemTitle.setText(accountBean.getType());
        itemMoney.setText(accountBean.getMoney().toString());
        itemTime.setText(String.valueOf(accountBean.getDay())+"号");
        return view;
    }

}
